package day1215_3;

import java.util.Random;

class  Thread1  extends  Thread{
    Object suo;
    public void run() {//wait停止   打印
        synchronized (suo){
            try {
                suo.wait();//让收到线程2通知，才能解除等待
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程1等待结束，继续运行");
        }
    }
}




class  Thread2  extends  Thread{//先打印，再通知另一个notify()
    Object suo;
    public void run() {
        System.out.println("线程2先运行的代码");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        synchronized (suo){
            suo.notify();
        }
    }
}




public class T2 {
    public static void main(String[] args) {
        Random  s=new Random();
        Thread1  t1=new Thread1();  t1.suo=s;  t1.start();
        Thread2  t2=new Thread2();  t2.suo=s;  t2.start();
    }
}






